<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Breakeven 
Description: A two-column, fixed-width design with dark color scheme.
Version    : 1.0
Released   : 20130509
-->

<?php
	session_start();  
	if (!isset($_SESSION['login'])) { 
	   header ('Location: ../index.html'); 
	   exit();  
	} 
	else
	{
		// on teste si le visiteur a soumis le formulaire
		if (isset($_POST['ok']) && $_POST['ok'] == 'OK') { 
		
			// on teste l'existence de nos variables. On teste également si elles ne sont pas vides
			if ((isset($_POST['nom']) && !empty($_POST['nom']))) { 
			
				$base = mysql_connect ('localhost', 'root', 'master'); 
				mysql_select_db ('easyimmo', $base); 

				// on recherche si ce login est déjà utilisé par un autre membre
				$sql = "SELECT count(*) FROM type_piece WHERE nom = '".mysql_real_escape_string($_POST['nom'])."';";
				$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
				
				$sql2 = "select MAX(id) as last FROM type_piece";
				$req2 = mysql_query($sql2) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
				
				$data = mysql_fetch_array($req); 
				$insertID = mysql_fetch_array($req2); 

				if ($data[0] == 0) { 
					$sql = "INSERT INTO type_piece VALUES(\"\",concat('ROOMTP','".$insertID['last']."'),'".mysql_real_escape_string($_POST['nom'])."')"; 
					mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 

					session_start(); 
					header('Location: pieces.php'); 
					exit(); 
				} 	
				else { 
					$erreur = 'Un type de pièce possède déjà ce nom !'; 
				} 
			} 
			else { 
				$erreur = 'Veuillez remplir tous les champs obligatoires !'; 
			}  
		} 
		if (isset($_POST['cancel']) && $_POST['cancel'] == 'Cancel') {		
			session_start(); 
			header('Location: pieces.php'); 
			exit(); 
		}
	} 
?>



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>EASY-Immo</title>
	
	<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600" rel="stylesheet" type="text/css" />
	<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'>
	<link href="../style.css" rel="stylesheet" type="text/css" media="screen" />
	<link rel="stylesheet" href="style-tableau.css" />
	
	<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
	<script type='text/javascript' src='../menu_jquery.js'></script>
	
</head>
	<body>
		<div id="wrapper">
			<!-- ==================================== HEADER ================================================== -->
			<div id="header-wrapper">
				<div id="header" class="container">
					<div id="logo">
						<h1><a href="index.html"><strong>EASY-Immo</strong></a></h1>
					</div>
					<div id="menu">
						<ul>
							<li class="current_page_item"><a href="membre.php">Bureau</a></li>
							<li><a href="administration.php">Administration</a></li>
							<li><a href="../deconnexion.php">Deconnexion</a></li>
						</ul>
					</div>
				</div>
			</div>
			<!-- end #header -->
			<!-- ============================================================================================= -->

			<div id="page">
				<h3>Bienvenue <?php echo " ".htmlentities(trim($_SESSION['nom']))." ".htmlentities(trim($_SESSION['prenom'])); ?>!</h3><br />
				Vous ête ici : <a href="membre.php">Données de réferences</a> / <a href="pieces.php">Types de pièces</a>
				
				<br><br><br>
				<br><br>
				
				<table>
					<tr>
						<td valign="top">
							<div id='cssmenu'>
								<ul>
								   <li><span></span></li>
								   <li class='has-sub'><a href='#'><span>Données de réferences</span></a>
									  <ul>
										 <li><a href='pieces.php'><span>Types de pièces</span></a></li>
										 <li><a href='#'><span>Types de documents</span></a></li>
										 <li><a href='#'><span>Types de comptes</span></a></li>
										 <li><a href='#'><span>Types de travaux</span></a></li>
										 <li><a href='#'><span>Parcelles</span></a></li>
										 <li><a href='#'><span>Contrats</span></a></li>
										 <li class='last'><a href='#'><span>Logements</span></a></li>
									  </ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Locataires</span></a>
									  <ul>
											<li><a href='#'><span>Nouveau locataire</span></a></li>
											<li class='last'><a href='#'><span>Afficher les locataires</span></a></li>
									  </ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Documents</span></a>								  
										<ul>
											<li><a href='#'><span>Afficher les documents</span></a></li>
											<li><a href='#'><span>Scanner un document</span></a></li>
											<li><a href='#'><span>Afficher les quittances</span></a></li>
											<li><a href='#'><span>Enregistrer une facture</span></a></li>
											<li><a href='#'><span>Créer une quittance</span></a></li>
											<li class='last'><a href='#'><span>Imprimer un document</span></a></li>
										</ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Maintenance</span></a>
									  <ul>
											<li><a href='#'><span>Afficher les maintenances</span></a></li>
											<li><a href='#'><span>Consulter les états des lieux</span></a></li>
											<li class='last'><a href='#'><span>Planifier des travaux</span></a></li>
									  </ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Finance</span></a>
									  <ul>
											<li><a href='#'><span>Suivi budget</span></a></li>								  
											<li><a href='#'><span>Budgetisation</span></a></li>
											<li><a href='#'><span>Consommation energetique</span></a></li>
											<li><a href='#'><span>Mouvement ponctuel</span></a></li>
											<li><a href='#'><span>Planifier un mouvement</span></a></li>
											<li class='last'><a href='#'><span>Générer le bilan</span></a></li>
									  </ul>							   
								   </li>							   
								   <li class='has-sub'><a href='#'><span>Comptabilité</span></a>
									  <ul>
											<li><a href='#'><span>Créer un compte</span></a></li>									  
											<li><a href='#'><span>Consulter les comptes</span></a></li>
											<li><a href='#'><span>Consulter les cautions</span></a></li>
											<li><a href='#'><span>Afficher les versements</span></a></li>
											<li><a href='#'><span>Suivre les versements</span></a></li>
											<li><a href='#'><span>Enregistrer un versement</span></a></li>
											<li><a href='#'><span>Enregistrer une dépense</span></a></li>
											<li><a href='#'><span>Déclaration fiscale</span></a></li>
											<li class='last'><a href='#'><span>Planifier des versements</span></a></li>
									  </ul>							   
								   </li>
								   <li class='has-sub'><a href='#'><span>Sécurité</span></a>
									  <ul>
										 <li><a href='#'><span>Droits</span></a></li>
										 <li><a href='#'><span>Roles</span></a></li>
										 <li><a href='#'><span>Profils</span></a></li>
										 <li class='last'><a href='#'><span>Utilisateurs</span></a></li>
									  </ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Rechercher</span></a>
									  <ul>
										 <li><a href='#'><span>Rechercher un compte</span></a></li>
										 <li><a href='#'><span>Rechercher un contrat</span></a></li>
										 <li><a href='#'><span>Rechercher un versement</span></a></li>
										 <li><a href='#'><span>Rechercher un document</span></a></li>
										 <li class='last'><a href='#'><span>Rechercher un locataire</span></a></li>
									  </ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Rapport</span></a>
									  <ul>
										 <li><a href='#'><span>Consulter le journal</span></a></li>
										 <li><a href='#'><span>Consommation Eau</span></a></li>
										 <li><a href='#'><span>Consommation Electricité</span></a></li>
										 <li class='last'><a href='#'><span>Exporter un rapport</span></a></li>
									  </ul>
								   </li>
								   <li class='has-sub'><a href='#'><span>Alertes</span></a>
									  <ul>
										 <li><a href='#'><span>Afficher les alertes</span></a></li>
										 <li class='last'><a href='#'><span>Créer une alerte</span></a></li>
									  </ul>	
								   </li>
								   <li class='last'><span></span></li>
								</ul>
							</div>										
						</td>
						<td align="left" valign="top">
							<div>
								<form style="" action="addTypePieces.php" method="post">
									<?php
										if (isset($erreur)){ echo '<h4 style="padding: 3px 20px 15px 200px; color:red">'.$erreur.'<h4>';}
									?>
									<table border="0" class="sortable2">
										<tr>
											<th style="padding: 3px 5px 3px 5px;">Nom* </th>
											<td><input size="80" style="padding: 3px 7px 3px 5px; " type="text" name="nom" value=""></td>
										</tr>	
										<tr>										
											<td colspan="2">
													<input size="10" class="orangebutton" type="submit" name="ok" value="OK" />
													<input size="10" class="greybutton" type="submit" name="cancel" value="Cancel" />
											</td>
										</tr>
									</table>
								</form>									
							</div>									
						</td>
					</tr>
				</table>
				<div style="clear: both; float: none; height: 0;"></div>		
				<!-- end #content -->			
			</div>
			<!-- end #page --> 
		</div>
		<br><br><br><br><br><br><br><br><br>
		<div id="footer">
			<p>Copyright (c) 2013 easy-immo.com. All rights reserved.</p>
		</div>
		<!-- end #footer -->
	</body>
</html>
